package ua.races.dom.docBuilder;

import org.jdom.Element;
import ua.races.vo.Horse;

import java.util.List;
import java.util.ListIterator;

public class HorseDocumentBuilder extends DocumentBuilder {
    protected List<Horse> horses;

    public HorseDocumentBuilder(List<Horse> horses) {
        this.horses = horses;
    }

    public void build() {
        Horse horse = null;

        Element root = new Element("Horses");

        ListIterator<Horse> iterator = horses.listIterator();

        while (iterator.hasNext()) {
            Element horseElement = new Element("horse");
            horse = iterator.next();

            Element horseId = new Element("HorseID");
            horseId.setText(String.valueOf(horse.getHorseId()));
            horseElement.addContent(horseId);

            Element horseName = new Element("HorseName");
            horseName.setText(horse.getHorseName());
            horseElement.addContent(horseName);

            root.addContent(horseElement);
        }

        document.addContent(root);

    }
}

